<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Coroutine TRY operation - Boost.Outcome documentation</title>
<link rel="stylesheet" href="../../../css/boost.css" type="text/css">
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

<link rel="icon" href="../../../images/favicon.ico" type="image/ico"/>
<body><div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/essential/coroutines/awaitables.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content">
  <div class="titlepage"><div><div><h1 style="clear: both">Coroutine TRY operation</h1></div></div></div>
  <p>As one cannot call statement <code>return</code> from within a Coroutine, the very first part of Outcome&rsquo;s
support for Coroutines is <a href="../../../reference/macros/co_tryv.html" class="api-reference"><code>BOOST_OUTCOME_CO_TRYV(expr)/BOOST_OUTCOME_CO_TRY(expr)</code></a>
,
which is literally the same as <code>BOOST_OUTCOME_TRY()</code> except that <code>co_return</code> is called
to return early instead of <code>return</code>.</p>
<div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="n">eager</span><span class="o">&lt;</span><span class="n">result</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&gt;&gt;</span> <span class="n">to_string</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">if</span><span class="p">(</span><span class="n">x</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span>
  <span class="p">{</span>
    <span class="n">BOOST_OUTCOME_CO_TRY</span><span class="p">(</span><span class="n">convert</span><span class="p">(</span><span class="n">x</span><span class="p">));</span>
  <span class="p">}</span>
  <span class="n">co_return</span> <span class="s">&#34;out of range&#34;</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>

        </div><p><small>Last revised: April 07, 2020 at 10:22:38 &#43;0100</small></p>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/essential/coroutines.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/essential/coroutines/awaitables.html"><img src="../../../images/next.png" alt="Next"></a></div></body>
</html>
